//Source file for the 3 component color definition
#include "Color3.h"
#include<math.h>

//constructors
Color3::Color3() { r = g = b = 0.0f; }
Color3::Color3(float _a, float _b, float _c)
{
	r = _a;
	g = _b;
	b = _c;
}

//functions

//Gamma correct the color components
void Color3::GammaCorrect(float gamma)
{
	float inv_gamma = 1/gamma;
	r = pow(r, inv_gamma);
	g = pow(g, inv_gamma);
	b = pow(b, inv_gamma);
}

//operators

//Invert the colors
Color3 Color3::operator - () { return Color3(-r, -g, -b); }

//Binary operators
Color3 Color3::operator + (Color3& C) { return Color3(r+C.r, g+C.g, b+C.b); }
Color3 Color3::operator - (Color3& C) { return Color3(r-C.r, g-C.g, b-C.b); }
Color3 Color3::operator* (float k) { return Color3(k*r, k*g, k*b); }
Color3 Color3::operator* (Color3& C) { return Color3(r*C.r, g*C.g, b*C.b); }
Color3 Color3::operator/ (float k) { return Color3(r/k, g/k, b/k); }
Color3 Color3::operator/ (Color3& C) { return Color3(r/C.r, g/C.g, b/C.b); }

RGB255 Color3::GetRGB255()
{
	RGB255 temp;
	temp.r = unsigned char (r < 0.0f? 0: (r > 1.0f? 255: r*255));
	temp.g = unsigned char (g < 0.0f? 0: (g > 1.0f? 255: g*255));
	temp.b = unsigned char (b < 0.0f? 0: (b > 1.0f? 255: b*255));
	return temp;
}


//Utility function
RGB255 Color3Byte(Color3& C)
{
	RGB255 temp;
	temp.r = unsigned char (C.r < 0.0f? 0: (C.r > 1.0f? 255: C.r*255));
	temp.g = unsigned char (C.g < 0.0f? 0: (C.g > 1.0f? 255: C.g*255));
	temp.b = unsigned char (C.b < 0.0f? 0: (C.b > 1.0f? 255: C.b*255));
	return temp;
}





